#include "bsp_config.h"

/***********************这里写一些关于控制的函数  风机开关  烧毁电阻  加热PID***********************/

/**
  * @brief  配置控制相关的GPIO管脚(针对开关量和PWM)  给自己一点保护色
  * @param  无
  * @retval 无
  */
static void Control_Relative_GPIO_Config(void)
{
  gpio_config_t io_conf;

  io_conf.intr_type = GPIO_INTR_DISABLE;
  io_conf.mode = GPIO_MODE_OUTPUT;
  //bit mask of the pins that you want to set,e.g.GPIO18/19
  io_conf.pin_bit_mask = (1ULL << DESTROY_GPIO) | (1ULL << PUMP_GPIO) | (1ULL << FAN_GPIO)|(1ULL << HEAT_GPIO); //
  //disable pull-down mode
  io_conf.pull_down_en = 0;
  //disable pull-up mode
  io_conf.pull_up_en = 0;
  //configure GPIO with the given settings
  gpio_config(&io_conf);

  gpio_set_level(DESTROY_GPIO, 0);
  gpio_set_level(PUMP_GPIO, 0);
  gpio_set_level(HEAT_GPIO, 0);
  gpio_set_level(FAN_GPIO, 0);

  
}

/**
 *  @brief PID PWM初始化
 *  @param 无
 *  @brief 无  
 */
static void PID_PWM_Config(void)
{
  /*
     * Prepare and set configuration of timers
     * that will be used by LED Controller
     */
  ledc_timer_config_t ledc_timer = {
      .duty_resolution = LEDC_TIMER_10_BIT, // resolution of PWM duty
      .freq_hz = 1,                         // frequency of PWM signal
      .speed_mode = LEDC_LOW_SPEED_MODE,    // timer mode
      .timer_num = LEDC_TIMER_3,            // timer index
      .clk_cfg = LEDC_AUTO_CLK,             // Auto select the source clock
  };
  // Set configuration of timer0 for high speed channels
  ledc_timer_config(&ledc_timer);

  /*
     * Prepare individual configuration
     * for each channel of LED Controller
     * by selecting:
     * - controller's channel number
     * - output duty cycle, set initially to 0
     * - GPIO number where LED is connected to
     * - speed mode, either high or low
     * - timer servicing selected channel
     *   Note: if different channels use one timer,
     *         then frequency and bit_num of these channels
     *         will be the same
     */
  ledc_channel_config_t ledc_channel = {
      .channel = LEDC_CHANNEL_2,
      .duty = 0, //初始脉冲宽度为0
      .gpio_num = PID_HEAT_GPIO,
      .speed_mode = LEDC_LOW_SPEED_MODE,
      .hpoint = 0,
      .timer_sel = LEDC_TIMER_3,
  };

  // Set LED Controller with previously prepared configuration
  ledc_channel_config(&ledc_channel);

  // Initialize fade service.
  ledc_fade_func_install(0);
}

/**
  * @brief  控制相关的外设初始化
  * @param  无
  * @retval 无
  */
void ControlInit(void)
{
  Control_Relative_GPIO_Config(); //
  PID_PWM_Config();
  PID_Init();
}

/**
 *  @brief 设置PID加热用的PWM脉冲宽度
 *  @param 无
 *  @brief duty 占空比 0~1000  
 */
void SetPIDPWMPulseWidth(uint32_t duty)
{
  if (duty > 1000)
  {
    ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_2, 0);
    ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_2);
  }
  else
  {
    ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_2, duty);
    ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_2);
  }
}

/**
  * @brief 泵开关函数              
  * @param  En: 1开泵   0关泵
  * @retval 无
  */
void PumpControl(uint8_t En)
{
  if (En)
  {
    gpio_set_level(PUMP_GPIO, 1);
  }
  else
  {
    gpio_set_level(PUMP_GPIO, 0);
  }
}

/**
  * @brief  电蚊香加热开关函数                
  * @param  En: 1:开  0:关
  * @retval 无
  */
void HeatControl(uint8_t En)
{
  if (En)
  {
    gpio_set_level(HEAT_GPIO, 1);
  }
  else
  {
    gpio_set_level(HEAT_GPIO, 0);
  }
}

/**
  * @brief  烧毁电阻开关函数                
  * @param  En: 1:开  0:关
  * @retval 无
  */
void DestroyControl(uint8_t En)
{
  if (En)
  {
    gpio_set_level(DESTROY_GPIO, 1);
  }
  else
  {
    gpio_set_level(DESTROY_GPIO, 0);
  }
}

/**
  * @brief  开风扇开关函数                
  * @param  En: 1:开  0:关
  * @retval 无
  */
void FanControl(uint8_t En)
{
  if (En)
  {
    gpio_set_level(FAN_GPIO, 1);
  }
  else
  {
    gpio_set_level(FAN_GPIO, 0);
  }
}

/**
  * @brief  加热PID控制(根据??标温度??,以及当下的NTC电阻温度值控制定时器的脉??) 定时调用            
  * @param  En: 1:开PID加热  0:关PID加热
  * @retval 无
  */
void HeatPIDControl(uint8_t En)
{
  if (En)
  {
    PID_Run_Flag = 1; //
  }
  else
  {
    PID_Run_Flag = 0; //
  }
}

volatile uint8_t PumpRunFlag = 0;

/**
  * @brief  设定泵电机转动的圈数         
  * @param  LoopCnt:要求泵转的圈数
  * @retval 无
  */
void SetPumpLoop(uint32_t LoopCnt)
{
  if (PumpRunFlag == 0)
  { //电机处于非运行状态
    PumpTargetCnt = LoopCnt + ConfigParam.PumpCnt.pump_cnt_data.pumpcnt;
    PumpRunFlag = 1; //该标志位会在电机运行指定的圈数后清0
    PumpControl(1);
  }
}

uint8_t notify_flag = 0; //提示药瓶没有安装好标志

/**                                      
  * @brief  判断当前药剂种类,总共有三种药剂    在开启熏蒸之前调用,在进入设置熏蒸面积时使用 简易版的灭蚊器以及ESP32版的灭蚊器,它的下面电阻值为590R
  *         如果是新瓶子则   对应电压 668.5mV     空瓶子和463.0之间相隔205.5         电压值得重新计算
  *         药瓶上电阻4.7K  对应电压463.0mV       药剂1  低效  和343.8之间相隔 119.2        15.29K
  *         药瓶上电阻10K   对应电压343.8mV       药剂2  中效  和217.2之间相隔 126.6      20.59K
  *         药瓶上电阻22K   对应电压217.2mV       药剂3  高效                            32.59K
  * 
  * @param  无
  * @retval 无
  */
void MedicineBottleResistor(void)
{
  uint32_t dat_buff;
  uint8_t is_new1 = 0;
  uint8_t i = 0;
  portMUX_TYPE GetResistorType_lock = portMUX_INITIALIZER_UNLOCKED;

  ENCRYPTION_Adc(); //实时更新药瓶AD值

  taskENTER_CRITICAL(&GetResistorType_lock);
  dat_buff = DESTROY_ADC_Value;          //这个值会每1s刷新5次
  dat_buff = dat_buff * 8000UL / 4096UL; //实际值就是800mV
  taskEXIT_CRITICAL(&GetResistorType_lock);
  ENCRYPTION_Adc(); //实时更新药瓶AD值

  taskENTER_CRITICAL(&GetResistorType_lock);
  dat_buff = DESTROY_ADC_Value;          //这个值会每1s刷新5次
  dat_buff = dat_buff * 8000UL / 4096UL; //实际值就是800mV
  taskEXIT_CRITICAL(&GetResistorType_lock);

  taskENTER_CRITICAL(&GetResistorType_lock);
  if (5685 < dat_buff)
  { //表示可能是新瓶子
    is_new1 = 1;
  }
  else
  { //表示不是新瓶子
    is_new1 = 0;
  }
  taskEXIT_CRITICAL(&GetResistorType_lock);

  if (is_new1 == 1)
  { //当可能为新瓶子时,开始烧电阻
    printf("new bottle!\n");
    gpio_set_level(DESTROY_GPIO, 1);
    vTaskDelay(300 / portTICK_PERIOD_MS); //烧保险持续300ms  不行改成1000
    gpio_set_level(DESTROY_GPIO, 0);
    vTaskDelay(200 / portTICK_PERIOD_MS); //等待200ms
  }
  //上面烧完了电阻
  /***********************************************************************************************/
  for (i = 0; i < 6; ++i)
  {
    printf("for %d\n", i);
    ENCRYPTION_Adc(); //实时更新药瓶AD值

    taskENTER_CRITICAL(&GetResistorType_lock);
    dat_buff = DESTROY_ADC_Value;          //这个值会每1s刷新5次
    dat_buff = dat_buff * 8000UL / 4096UL; //实际值就是800mV
    taskEXIT_CRITICAL(&GetResistorType_lock);

    ENCRYPTION_Adc(); //实时更新药瓶AD值

    taskENTER_CRITICAL(&GetResistorType_lock);
    dat_buff = DESTROY_ADC_Value;          //这个值会每1s刷新5次
    dat_buff = dat_buff * 8000UL / 4096UL; //实际值就是800mV
    taskEXIT_CRITICAL(&GetResistorType_lock);

    printf("VCC:%d\n", dat_buff);
    if (4130 < dat_buff && dat_buff < 5130)
    { //对应电压463.0mV     药剂1 低效药剂
      //这里可以对药剂进行指示了
      if (is_new1 == 1)
      { //表示安装了新瓶子
        is_new1 = 0;

        PumpTargetCnt = 0;
        ConfigParam.PumpCnt.pump_cnt_data.is_empty = NOT_EMPTY;
        ConfigParam.PumpCnt.pump_cnt_data.pumpcnt = 0; //泵计数归零
        ConfigParam.PumpCnt.pump_cnt_data.type = NORMAL_MEDICINE;
        ConfigParam.PumpCnt.pump_cnt_data.need_evacuation = NEED_EVACU; //新瓶子需要排空气标志
        printf("NOT_EMPTY NORMAL_MEDICINE  NEED_EVACU\r\n");
        write_config_param(&ConfigParam.PumpCnt.pump_cnt_data.pumpcnt, ConfigParam.PumpCnt.pC, ConfigParam.PumpCnt.length);
      }
      notify_flag = 0; //瓶子装好了,不用提示
      goto des;        //准备退出
    }
    else if (2938 < dat_buff && dat_buff < 3938)
    { //对应电压343.8mV     药剂2  中效
      //这里可以对药剂进行指示了
      if (is_new1 == 1)
      { //表示安装了新瓶子
        is_new1 = 0;

        PumpTargetCnt = 0;
        ConfigParam.PumpCnt.pump_cnt_data.is_empty = NOT_EMPTY;
        ConfigParam.PumpCnt.pump_cnt_data.pumpcnt = 0; //泵计数归零
        ConfigParam.PumpCnt.pump_cnt_data.type = MEDIAN_MEDICINE;
        ConfigParam.PumpCnt.pump_cnt_data.need_evacuation = NEED_EVACU; //新瓶子需要排空气标志
        printf("NOT_EMPTY MEDIAN_MEDICINE  NEED_EVACU\r\n");
        write_config_param(&ConfigParam.PumpCnt.pump_cnt_data.pumpcnt, ConfigParam.PumpCnt.pC, ConfigParam.PumpCnt.length);
      }
      notify_flag = 0; //瓶子装好了,不用提示
      goto des;        //准备退出
    }
    else if (1672 < dat_buff && dat_buff < 2672)
    { //对应电压217.2mV     药剂1  高效
      //这里可以对药剂进行指示了
      if (is_new1 == 1)
      { //表示安装了新瓶子
        is_new1 = 0;

        PumpTargetCnt = 0;
        ConfigParam.PumpCnt.pump_cnt_data.is_empty = NOT_EMPTY;
        ConfigParam.PumpCnt.pump_cnt_data.pumpcnt = 0; //泵计数归零
        ConfigParam.PumpCnt.pump_cnt_data.type = ENCHANCE_MEDICINE;
        ConfigParam.PumpCnt.pump_cnt_data.need_evacuation = NEED_EVACU; //新瓶子需要排空气标志
        printf("NOT_EMPTY ENCHANCE_MEDICINE  NEED_EVACU\r\n");
        write_config_param(&ConfigParam.PumpCnt.pump_cnt_data.pumpcnt, ConfigParam.PumpCnt.pC, ConfigParam.PumpCnt.length);
      }
      notify_flag = 0; //瓶子装好了,不用提示
      goto des;        //准备退出
    }
    vTaskDelay(50 / portTICK_PERIOD_MS); //等待50ms
  }
  /***********************************************************************************************/
  //能到这一步说明没有装瓶子,或者探针没有接好
  notify_flag = 1; //将药瓶没有安装好标志位置1
  // OpenOptionLED();
  printf("瓶盖没有装好!");
des:;
  // Fumigate_Area_Indicate(); //指示当前面积
}

uint8_t timing_repel_pause = 0; //针对定时模式的
uint8_t repel_once_mark = 0;

WORKING_STEP_Typedef working_step = STEP_ALL; //状态???录用变??(小???)        ConfigParam.WorkingMode.working_mode这个??大???
uint16_t second_cnt = 0;                      //延时??动没必???那么精??
uint16_t second_cnt_buff = 0;


#define  TIMES        6
#define  INTERVAL     60


/**
  * @brief  主是针对普通熏蒸
  * @param  无
  * @retval 无
  */
void FumigateNormal(void)
{
  static uint32_t medicine_quantity = 0;

  if (ConfigParam.WorkingMode.work_mode_data.working_mode == ENUM_FUMIGATE_NORMAL_MODE)
  {
    if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_READY)
    {
      ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_START;
      working_step = STEP2;     //
      MedicineBottleResistor(); //探测药剂的种类
      if (ConfigParam.PumpCnt.pump_cnt_data.is_empty == IS_EMPTY || notify_flag == 1)
      { //没药了或者 药瓶没装好
        ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_STOP;
        IsChangeMenu = true; //重绘界面

        if (notify_flag == 1)
        {
          //向APP发送瓶子没有装好提示
          mqtt_pub_queue_enum = MQTT_SEND_BOTTLE_UNINSTALL;
          pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
          if (mqtt_is_connected == MQTT_CONNECTED)
          {
            xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
          }
        }
        else if (ConfigParam.PumpCnt.pump_cnt_data.is_empty == IS_EMPTY)
        { //向APP发送当前药剂为空提示(实际是发送当前状态)
          mqtt_pub_queue_enum = MQTT_SEND_STATE;
          pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
          if (mqtt_is_connected == MQTT_CONNECTED)
          {
            xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
          }
        }

        return;
      }
      //这里可以进行变温度操作

      if (ConfigParam.PumpCnt.pump_cnt_data.need_evacuation == NEED_EVACU)
      { //需要排空气
        SetPumpLoop(ConfigParam.FactorySetting.factory_sett_data.evacuation_times);
      }
    }
    else if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_WAIT)
    { //这里为等待状态
      if (second_cnt > 30 * 60)
      { //剩余30min
        second_cnt--;
      }
      if (working_step == STEP5)
      {
        //下面进行变温操作
        // if ((second_cnt_buff - second_cnt) == 300)
        // { //过了5min 300s
        //   ConfigParam.PID_Param.SetPoint.dat_f = ConfigParam.PID_Param.SetPointBackup.dat_f - 45.0;
        //   ConfigParam.PID_Param.Self_Tuning_Flag = 1; //开始自整定
        //   ee_WriteBytes((uint8_t *)&ConfigParam.PID_Param.SetPoint.dat_f, ConfigParam.PID_Param.pid_addr, PID_PARAM_LENGTH);
        //   PID_Init(); //主要是为了实时更新,sPID.SetPoint的值
        // }
        if ((second_cnt_buff - second_cnt) % INTERVAL == 0)
        { //每1minute秒喷一次
          if (medicine_quantity >= TIMES)
          {
            SetPumpLoop(TIMES); //TIMES
            medicine_quantity -= TIMES;
          }
          else if (medicine_quantity > 0)
          {                                 //到这里说明 TIMES> medicine_quantity >0
            SetPumpLoop(medicine_quantity); //有多少喷多少
            medicine_quantity = 0;
          }
        }
        if (second_cnt <= 30 * 60)
        { //熏蒸结束,开启风扇30min
          ConfigParam.WorkingStatus.working_status_data = ENUM_FAN_WORKING;
        }
      }
    }
    else if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_START)
    {
      if (working_step == STEP2)
      {                    //这一步可以开风机,加热
        FanControl(1);     //风机全开
        HeatPIDControl(1); //开始加热
        working_step = STEP3;
      }
      if (working_step == STEP3)
      { //
        if ((ConfigParam.PID_Param.pid_param_data.Self_Tuning_Flag == 0) && ((uint16_t)CurrentTemp > (uint32_t)(ConfigParam.PID_Param.pid_param_data.SetPoint - 5)))
        { //PID整定完成,并且当前温度大于170度                                                                                                                                //pid整定完成,并且温度达到了???求 。，
          switch (ConfigParam.FumigateSetting.fumi_sett_data.fumi_sett_area)
          {                    //下面根据设置选项，选择对应的药剂量
          case ENUM_0_15_M2_F: //房间面积  (0-15m2)
            medicine_quantity = (15UL * ConfigParam.FumigateSetting.fumi_sett_data.fumi_house_height) * ConfigParam.FactorySetting.factory_sett_data.timers_per10m3 / 10 + 0.9F;
            break;
          case ENUM_15_30_M2_F: //房价面积  (15-30m2)
            medicine_quantity = (30UL * ConfigParam.FumigateSetting.fumi_sett_data.fumi_house_height) * ConfigParam.FactorySetting.factory_sett_data.timers_per10m3 / 10 + 0.9F;
            break;
          case ENUM_30_50_M2_F: //房间面积  (30-50m2)
            medicine_quantity = (50UL * ConfigParam.FumigateSetting.fumi_sett_data.fumi_house_height) * ConfigParam.FactorySetting.factory_sett_data.timers_per10m3 / 10 + 0.9F;
            break;
          case ENUM_50_80_M2_F: //房间面积  (50-80m2)
            medicine_quantity = (80UL * ConfigParam.FumigateSetting.fumi_sett_data.fumi_house_height) * ConfigParam.FactorySetting.factory_sett_data.timers_per10m3 / 10 + 0.9F;
            break;
          case ENUM_80_100_M2_F: //房间面积  (80-100m2)
            medicine_quantity = (100UL * ConfigParam.FumigateSetting.fumi_sett_data.fumi_house_height) * ConfigParam.FactorySetting.factory_sett_data.timers_per10m3 / 10 + 0.9F;
            break;
          case ENUM_100_150_M2_F: //房间面积  (100-150m2)
            medicine_quantity = (150UL * ConfigParam.FumigateSetting.fumi_sett_data.fumi_house_height) * ConfigParam.FactorySetting.factory_sett_data.timers_per10m3 / 10 + 0.9F;
            break;
          case ENUM_150_200_M2_F: //房间面积  (150-200m2)
            medicine_quantity = (200UL * ConfigParam.FumigateSetting.fumi_sett_data.fumi_house_height) * ConfigParam.FactorySetting.factory_sett_data.timers_per10m3 / 10 + 0.9F;
            break;
          default:
            medicine_quantity = (200UL * ConfigParam.FumigateSetting.fumi_sett_data.fumi_house_height) * ConfigParam.FactorySetting.factory_sett_data.timers_per10m3 / 10 + 0.9F;
            break;
          }
          float times = 2.0;

          switch (ConfigParam.PumpCnt.pump_cnt_data.type)
          {
          case NORMAL_MEDICINE:
            times = 2.0;
            break;
          case MEDIAN_MEDICINE:
            times = 1.5;
            break;
          case ENCHANCE_MEDICINE:
            times = 1.0;
            break;
          default:
            times = 2.0;
            break;
          }
          medicine_quantity = medicine_quantity * times + 0.9F; //增强模式是普通模式的1.2倍

          if (medicine_quantity >= TIMES)
          {
            SetPumpLoop(TIMES); //TIMES
            medicine_quantity -= TIMES;
          }
          else if (medicine_quantity > 0)
          {                                 //到这里说明 TIMES> medicine_quantity >0
            SetPumpLoop(medicine_quantity); //有多少喷多少
            medicine_quantity = 0;
          }

          working_step = STEP4;
        }
        else
        {
          //这里蜂鸣器响三声
          beep_queue_enum = BEEP_THREE;
          pBEEP_QUEUE_ENUM = &beep_queue_enum;
          xQueueSend(beep_QueueHandler, (void *)&pBEEP_QUEUE_ENUM, portMAX_DELAY);
        }
      }
      if (working_step == STEP4)
      {                                                                                                        //这里设置一??定时??,用来设定什么时候停??
        second_cnt_buff = second_cnt = (ConfigParam.FactorySetting.factory_sett_data.fumigate_time + 30) * 60; //需要工作的时间,还得外加30min
        ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_WAIT;                                     //进入到监??
        working_step = STEP5;
      }
    }
    else if (ConfigParam.WorkingStatus.working_status_data == ENUM_FAN_WORKING)
    {
      working_step = STEP_ALL; //状态复位
      HeatPIDControl(0);       //关闭加热

      if (second_cnt > 0)
      {
        second_cnt--;
      }
      if (second_cnt == 0)
      {
        FanControl(0); //关风机
        ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_STOP;
        IsChangeMenu = true; //刷新当前显示界面

        //发送当前的状态
        mqtt_pub_queue_enum = MQTT_SEND_STATE;
        pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
        if (mqtt_is_connected == MQTT_CONNECTED)
        {
          xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
        }
      }
    }
    else if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_STOP)
    {
      second_cnt = 0;          //计时时间归零
      working_step = STEP_ALL; //状态???位
      HeatPIDControl(0);       //关闭加热
      FanControl(0);           //关风机
    }
  }
} //FumigateNormal

/**
  * @brief  主要是针对增强熏蒸
  * @param  无
  * @retval 无
  */
void FumigateEnchance(void)
{
  static uint32_t medicine_quantity = 0;

  if (ConfigParam.WorkingMode.work_mode_data.working_mode == ENUM_FUMIGATE_ENCHANCE_MODE)
  {
    if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_READY)
    {
      ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_START;
      working_step = STEP2; //
      MedicineBottleResistor();
      if (ConfigParam.PumpCnt.pump_cnt_data.is_empty == IS_EMPTY || notify_flag == 1)
      { //没药了或者 药瓶没装好
        ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_STOP;
        IsChangeMenu = true; //重绘界面

        // Send_bottle_uninstall();
        // Send_No_Fumigate_Medicine();
        // Send_No_Repel_Medicine();

        if (notify_flag == 1)
        {
          //向APP发送瓶子没有装好提示
          mqtt_pub_queue_enum = MQTT_SEND_BOTTLE_UNINSTALL;
          pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
          if (mqtt_is_connected == MQTT_CONNECTED)
          {
            xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
          }
        }
        else if (ConfigParam.PumpCnt.pump_cnt_data.is_empty == IS_EMPTY)
        { //向APP发送当前药剂为空提示(实际是发送当前状态)
          mqtt_pub_queue_enum = MQTT_SEND_STATE;
          pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
          if (mqtt_is_connected == MQTT_CONNECTED)
          {
            xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
          }
        }

        return;
      }
      // ConfigParam.PID_Param.SetPoint.dat_f = ConfigParam.PID_Param.SetPointBackup.dat_f;
      // ConfigParam.PID_Param.Self_Tuning_Flag = 1; //开始自整定
      // ee_WriteBytes((uint8_t *)&ConfigParam.PID_Param.SetPoint.dat_f, ConfigParam.PID_Param.pid_addr, PID_PARAM_LENGTH);
      // PID_Init(); //主要是为了实时更新,sPID.SetPoint的值
      if (ConfigParam.PumpCnt.pump_cnt_data.need_evacuation == NEED_EVACU)
      { //需要排空气
        SetPumpLoop(ConfigParam.FactorySetting.factory_sett_data.evacuation_times);
      }
    }
    else if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_WAIT)
    {
      if (second_cnt > 30 * 60)
      {
        second_cnt--;
      }
      // if ((second_cnt_buff - second_cnt) == 300)
      // { //过了5min
      //   ConfigParam.PID_Param.SetPoint.dat_f = ConfigParam.PID_Param.SetPointBackup.dat_f - 45.0;
      //   ConfigParam.PID_Param.Self_Tuning_Flag = 1; //开始自整定
      //   ee_WriteBytes((uint8_t *)&ConfigParam.PID_Param.SetPoint.dat_f, ConfigParam.PID_Param.pid_addr, PID_PARAM_LENGTH);
      //   PID_Init(); //主要是为了实时更新,sPID.SetPoint的值
      // }
      if (working_step == STEP5)
      {
        if ((second_cnt_buff - second_cnt) % INTERVAL == 0)
        { //每1minute秒喷一次
          if (medicine_quantity >= TIMES)
          {
            SetPumpLoop(TIMES); //TIMES次
            medicine_quantity -= TIMES;
          }
          else if (medicine_quantity > 0)
          {                                 //到这里说明 TIMES> medicine_quantity >0
            SetPumpLoop(medicine_quantity); //有多少喷多少
            medicine_quantity = 0;
          }
        }
        if (second_cnt <= 30 * 60)
        { //加热结束,但还得开启风扇30min
          ConfigParam.WorkingStatus.working_status_data = ENUM_FAN_WORKING;
        }
      }
    }
    else if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_START)
    {
      if (working_step == STEP2)
      {                    //这一步可以开风机,加热
        FanControl(1);     //风机全开
        HeatPIDControl(1); //开始加热
        working_step = STEP3;
      }
      if (working_step == STEP3)
      {
        if ((ConfigParam.PID_Param.pid_param_data.Self_Tuning_Flag == 0) && ((uint16_t)CurrentTemp > (uint32_t)(ConfigParam.PID_Param.pid_param_data.SetPoint - 5)))
        {
          switch (ConfigParam.FumigateSetting.fumi_sett_data.fumi_sett_area)
          {                    //下面根据设置选项，选择对应的药剂量
          case ENUM_0_15_M2_F: //房间面积  (0-15m2)
            medicine_quantity = (15UL * ConfigParam.FumigateSetting.fumi_sett_data.fumi_house_height) * ConfigParam.FactorySetting.factory_sett_data.timers_per10m3 / 10 + 0.9F;
            break;
          case ENUM_15_30_M2_F: //房价面积  (15-30m2)
            medicine_quantity = (30UL * ConfigParam.FumigateSetting.fumi_sett_data.fumi_house_height) * ConfigParam.FactorySetting.factory_sett_data.timers_per10m3 / 10 + 0.9F;
            break;
          case ENUM_30_50_M2_F: //房间面积  (30-50m2)
            medicine_quantity = (50UL * ConfigParam.FumigateSetting.fumi_sett_data.fumi_house_height) * ConfigParam.FactorySetting.factory_sett_data.timers_per10m3 / 10 + 0.9F;
            break;
          case ENUM_50_80_M2_F: //房间面积  (50-80m2)
            medicine_quantity = (80UL * ConfigParam.FumigateSetting.fumi_sett_data.fumi_house_height) * ConfigParam.FactorySetting.factory_sett_data.timers_per10m3 / 10 + 0.9F;
            break;
          case ENUM_80_100_M2_F: //房间面积  (80-100m2)
            medicine_quantity = (100UL * ConfigParam.FumigateSetting.fumi_sett_data.fumi_house_height) * ConfigParam.FactorySetting.factory_sett_data.timers_per10m3 / 10 + 0.9F;
            break;
          case ENUM_100_150_M2_F: //房间面积  (100-150m2)
            medicine_quantity = (150UL * ConfigParam.FumigateSetting.fumi_sett_data.fumi_house_height) * ConfigParam.FactorySetting.factory_sett_data.timers_per10m3 / 10 + 0.9F;
            break;
          case ENUM_150_200_M2_F: //房间面积  (150-200m2)
            medicine_quantity = (200UL * ConfigParam.FumigateSetting.fumi_sett_data.fumi_house_height) * ConfigParam.FactorySetting.factory_sett_data.timers_per10m3 / 10 + 0.9F;
            break;
          default:
            medicine_quantity = (200UL * ConfigParam.FumigateSetting.fumi_sett_data.fumi_house_height) * ConfigParam.FactorySetting.factory_sett_data.timers_per10m3 / 10 + 0.9F;
            break;
          }
          float times = 2.0;

          switch (ConfigParam.PumpCnt.pump_cnt_data.type)
          {
          case NORMAL_MEDICINE:
            times = 2.0;
            break;
          case MEDIAN_MEDICINE:
            times = 1.5;
            break;
          case ENCHANCE_MEDICINE:
            times = 1.0;
            break;
          default:
            times = 2.0;
            break;
          }
          medicine_quantity = medicine_quantity * 1.2F * times + 0.9F; //增强模式是普通模式的1.2倍
          if (medicine_quantity >= TIMES)
          {
            SetPumpLoop(TIMES); //TIMES次
            medicine_quantity -= TIMES;
          }
          else if (medicine_quantity > 0)
          {                                 //到这里说明 TIMES> medicine_quantity >0
            SetPumpLoop(medicine_quantity); //有多少喷多少
            medicine_quantity = 0;
          }
          working_step = STEP4;
        }
        else
        {
          //这里蜂鸣器响三声
          beep_queue_enum = BEEP_THREE;
          pBEEP_QUEUE_ENUM = &beep_queue_enum;
          xQueueSend(beep_QueueHandler, (void *)&pBEEP_QUEUE_ENUM, portMAX_DELAY);
        }
      }
      if (working_step == STEP4)
      {
        second_cnt_buff = second_cnt = (ConfigParam.FactorySetting.factory_sett_data.fumigate_time + 30) * 60; //需要工作的时间(正式的熏蒸时??)
        ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_WAIT;                                     //进入到监??
        working_step = STEP5;
      }
    }
    else if (ConfigParam.WorkingStatus.working_status_data == ENUM_FAN_WORKING)
    {
      working_step = STEP_ALL; //
      HeatPIDControl(0);       //关闭加热

      if (second_cnt > 0)
      {
        second_cnt--;
      }
      if (second_cnt == 0)
      {
        FanControl(0);
        ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_STOP;
        IsChangeMenu = true; //重绘界面

        //发送当前工作状态
        mqtt_pub_queue_enum = MQTT_SEND_STATE;
        pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
        if (mqtt_is_connected == MQTT_CONNECTED)
        {
          xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
        }
      }
    }
    else if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_STOP)
    {
      second_cnt = 0;          //计时时间归零
      working_step = STEP_ALL; //状态
      HeatPIDControl(0);       //关闭加热
      FanControl(0);           //
    }
  }
} //FumigateEnchance

uint8_t stop_refresh = 0;
uint8_t mark = 0; //这些变量得结合具体的情景来进行

/**
  * @brief  主是针对空调驱蚊
  * @param  无
  * @retval 无
  */
void RepelAirCondition(void)
{
  if (ConfigParam.WorkingMode.work_mode_data.working_mode == ENUM_REPEL_AIR_CONDI_MODE) //驱蚊
  {
    // ENUM_MOS_REPEL_NORMAL,
    // ENUM_MOS_REPEL_TIMING,
    if (ConfigParam.RepelSetting.repel_sett_data.repel_sett_mode == ENUM_MOS_REPEL_NORMAL)
    {
      if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_READY)
      {
        HeatControl(1);
        // FanControl(1);
        second_cnt = ConfigParam.FactorySetting.factory_sett_data.InitRepelTime * 60;
        working_step = STEP1;
        ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_WAIT;
      }
      else if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_WAIT)
      {
        if (second_cnt > 0)
        {
          second_cnt--;
        }
        if (working_step == STEP1)
        { //在这里等待驱蚊关,莫前的状态是驱蚊已经开启了
          if (second_cnt == 0)
          {
            ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_START;
            working_step = STEP2; //
          }
          if (ConfigParam.RepelSetting.repel_sett_data.total_repel_time > 0)
          {                                                              //如果还有驱蚊药剂的话
            ConfigParam.RepelSetting.repel_sett_data.total_repel_time--; //每隔1s药剂总时间,得减1
            if (ConfigParam.RepelSetting.repel_sett_data.total_repel_time % 1800 == 0)
            { //每个30min对药剂时间进行存储
              write_config_param(&ConfigParam.RepelSetting.repel_sett_data.repel_sett_mode, ConfigParam.RepelSetting.pC, ConfigParam.RepelSetting.length);
            }
          }
          else
          { //这里是驱蚊药水用完了的情况
            ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_STOP;
            IsChangeMenu = true; //重绘界面

            mqtt_pub_queue_enum = MQTT_SEND_STATE;
            pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
            if (mqtt_is_connected == MQTT_CONNECTED)
            {
              xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
            }
          }
        }
        if (working_step == STEP3)
        { //在这里等待驱蚊开,莫前的状态是驱蚊已经关闭了
          if (second_cnt == 0)
          {
            ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_START;
            working_step = STEP4;
          }
        }
      }
      else if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_START)
      {
        if (working_step == STEP2)
        { //关闭驱蚊！
          switch (ConfigParam.RepelSetting.repel_sett_data.repel_sett_area)
          {
          case ENUM_21_30_M2:
            second_cnt = ConfigParam.FactorySetting.factory_sett_data.area30m2_factory * ConfigParam.FactorySetting.factory_sett_data.air_condi_close_time * 60UL / 100;
            break;
          case ENUM_10_20_M2:
            second_cnt = ConfigParam.FactorySetting.factory_sett_data.area20m2_factory * ConfigParam.FactorySetting.factory_sett_data.air_condi_close_time * 60UL / 100;
            break;
          case ENUM_BENEATH_10M2:
            second_cnt = ConfigParam.FactorySetting.factory_sett_data.area10m2_factory * ConfigParam.FactorySetting.factory_sett_data.air_condi_close_time * 60UL / 100;
            break; //ENUM_AUTO_
          default:
            second_cnt = ConfigParam.FactorySetting.factory_sett_data.area30m2_factory * ConfigParam.FactorySetting.factory_sett_data.air_condi_close_time * 60UL / 100;
            break;
          }
          HeatControl(0);
          // FanControl(0);  //关???机
          ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_WAIT;
          working_step = STEP3;
        }
        if (working_step == STEP4)
        { //表示驱蚊开的时间
          switch (ConfigParam.RepelSetting.repel_sett_data.repel_sett_area)
          { //根据当前的面??来???算具体的驱蚊开关时??(这里表示关闭的时??)  这里的智能???测没有做
          case ENUM_21_30_M2:
            second_cnt = ConfigParam.FactorySetting.factory_sett_data.area30m2_factory * ConfigParam.FactorySetting.factory_sett_data.air_condi_open_time * 60UL / 100;
            break;
          case ENUM_10_20_M2:
            second_cnt = ConfigParam.FactorySetting.factory_sett_data.area20m2_factory * ConfigParam.FactorySetting.factory_sett_data.air_condi_open_time * 60UL / 100;
            break;
          case ENUM_BENEATH_10M2:
            second_cnt = ConfigParam.FactorySetting.factory_sett_data.area10m2_factory * ConfigParam.FactorySetting.factory_sett_data.air_condi_open_time * 60UL / 100;
            break;
          default:
            second_cnt = ConfigParam.FactorySetting.factory_sett_data.area30m2_factory * ConfigParam.FactorySetting.factory_sett_data.air_condi_open_time * 60UL / 100;
            break;
          }
          HeatControl(1); //开加热
          // FanControl(1);  //开风机
          ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_WAIT;
          working_step = STEP1;
        }
      }
      else if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_STOP)
      {
        //IsChangeMenu=true;  //重绘界面   这里不能重绘
        second_cnt = 0;
        working_step = STEP_ALL;
        HeatControl(0);
        // FanControl(0);
      }
    }
    else if (ConfigParam.RepelSetting.repel_sett_data.repel_sett_mode == ENUM_MOS_REPEL_TIMING)
    {                               //这里针对定时驱蚊的情况
      uint16_t current_minutes = 0; //当前分钟
      uint16_t start_minutes = 0;   //开始分钟
      uint16_t end_minutes = 0;     //结束分钟
      static uint8_t mark1 = 0;

      current_minutes = (current_time.tm_hour * (uint32_t)60) + current_time.tm_min; //这里向uint16_t转变是为了防止变量值溢出
      start_minutes = ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.Start_Hour * (uint16_t)60;
      end_minutes = ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.End_Hour * (uint16_t)60;

      if (ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.End_Hour > ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.Start_Hour)
      { //结束时间大于开始时间 的情况
        if (start_minutes <= current_minutes && current_minutes < end_minutes)
        {                              //注意这里的   <=  和 <号的使用       处于工作时间段内
          if (timing_repel_pause == 1) //       按下了启动键  这个按键的作用就是触发用的
          {
            if (ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.IsRepeat == true)
            { //点了每天,到点就开??       //有些参数变化,完成后得妥善保存
              mark = 1;
            }
            else if (repel_once_mark == 1)
            { //没有点每天
              repel_once_mark = 0;
              mark = 1;
            } //else if ()
          }   //if
        }     //if
        else
        { //否则停机
          mark = 0;
        } //else
      }   //if
      else if (ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.End_Hour < ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.Start_Hour)
      { //结束时间小于开始时间的情况   ,这种情况是指,隔天的情况
        if (!(start_minutes > current_minutes && current_minutes >= end_minutes))
        {                              //这里是从反方向来考虑的
          if (timing_repel_pause == 1) //       按下了启动键
          {
            if (ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.IsRepeat == true)
            { //点了每天,到点就开??
              mark = 1;
            }
            else if (repel_once_mark == 1)
            { //没有点每??
              repel_once_mark = 0;
              mark = 1;
            }
          }
        }
        else
        { //否则停机
          mark = 0;
        }
      }
      else
      {
        //否则停机
        mark = 0;
      }

      /**
       * 上面是监控函数
       */
      if (mark == 1)
      {                 //这里表示开机
        if (mark1 == 0) //一切从简,能用就OK
        {
          mark1 = 1; //为关机做准备
          ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_READY;
          IsChangeMenu = true; //这里得刷新一下显示
                               //这里得将工作状态发给APP
          mqtt_pub_queue_enum = MQTT_SEND_STATE;
          pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
          if (mqtt_is_connected == MQTT_CONNECTED)
          {
            xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
          }
        }
        else if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_READY)
        {
          HeatControl(1);
          // FanControl(1);
          second_cnt = ConfigParam.FactorySetting.factory_sett_data.InitRepelTime * 60;
          working_step = STEP1;
          ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_WAIT;
        }
        else if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_WAIT)
        {
          if (second_cnt > 0)
          {
            second_cnt--;
          }
          if (working_step == STEP1)
          { //在这里等待驱蚊加热关闭,(这段时间驱蚊加热是开启的)
            if (second_cnt == 0)
            {
              ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_START;
              working_step = STEP2; //
            }
            if (ConfigParam.RepelSetting.repel_sett_data.total_repel_time > 0)
            {                                                              //如果还有驱蚊药剂的话
              ConfigParam.RepelSetting.repel_sett_data.total_repel_time--; //每隔1s药剂总时间,得减1
              if (ConfigParam.RepelSetting.repel_sett_data.total_repel_time % 1800 == 0)
              { //每个30min对药剂时间进行存储
                write_config_param(&ConfigParam.RepelSetting.repel_sett_data.repel_sett_mode, ConfigParam.RepelSetting.pC, ConfigParam.RepelSetting.length);
              }
            }
            else
            {                         //这里是驱蚊药水已经用完了的情况
              timing_repel_pause = 0; //定时驱蚊暂停
              mark = 0;               //按下停止键时不管三七二十一直接停止
              stop_refresh = 1;
            }
          }
          if (working_step == STEP3)
          { //在这里等待驱蚊加热开启,(这段时间驱蚊加热是关闭的)
            if (second_cnt == 0)
            {
              ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_START;
              working_step = STEP4;
            } //if
          }   //if
        }
        else if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_START)
        { //进入到这一步,表示关加热
          if (working_step == STEP2)
          {
            switch (ConfigParam.RepelSetting.repel_sett_data.repel_sett_area)
            {
            case ENUM_21_30_M2:
              second_cnt = ConfigParam.FactorySetting.factory_sett_data.area30m2_factory * ConfigParam.FactorySetting.factory_sett_data.air_condi_close_time * 60UL / 100;
              break;
            case ENUM_10_20_M2:
              second_cnt = ConfigParam.FactorySetting.factory_sett_data.area20m2_factory * ConfigParam.FactorySetting.factory_sett_data.air_condi_close_time * 60UL / 100;
              break;
            case ENUM_BENEATH_10M2:
              second_cnt = ConfigParam.FactorySetting.factory_sett_data.area10m2_factory * ConfigParam.FactorySetting.factory_sett_data.air_condi_close_time * 60UL / 100;
              break;
            default:
              second_cnt = ConfigParam.FactorySetting.factory_sett_data.area30m2_factory * ConfigParam.FactorySetting.factory_sett_data.air_condi_close_time * 60UL / 100;
              break;
            }
            HeatControl(0);
            // FanControl(0);  //关???机
            ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_WAIT;
            working_step = STEP3;
          }
          if (working_step == STEP4)
          { //进入到这一步,表示开加热
            switch (ConfigParam.RepelSetting.repel_sett_data.repel_sett_area)
            {
            case ENUM_21_30_M2:
              second_cnt = ConfigParam.FactorySetting.factory_sett_data.area30m2_factory * ConfigParam.FactorySetting.factory_sett_data.air_condi_open_time * 60UL / 100;
              break;
            case ENUM_10_20_M2:
              second_cnt = ConfigParam.FactorySetting.factory_sett_data.area20m2_factory * ConfigParam.FactorySetting.factory_sett_data.air_condi_open_time * 60UL / 100;
              break;
            case ENUM_BENEATH_10M2:
              second_cnt = ConfigParam.FactorySetting.factory_sett_data.area10m2_factory * ConfigParam.FactorySetting.factory_sett_data.air_condi_open_time * 60UL / 100;
              break;
            default:
              second_cnt = ConfigParam.FactorySetting.factory_sett_data.area30m2_factory * ConfigParam.FactorySetting.factory_sett_data.air_condi_open_time * 60UL / 100;
              break;
            }
            HeatControl(1); //开加热
            // FanControl(1);  //开风机
            ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_WAIT;
            working_step = STEP1;
          }
        }
      }
      else if (mark == 0)
      {
        if (mark1 == 1 || stop_refresh == 1)
        {
          mark1 = 0;
          stop_refresh = 0;
          ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_STOP;
          IsChangeMenu = true; //重绘界面

          mqtt_pub_queue_enum = MQTT_SEND_STATE;
          pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
          if (mqtt_is_connected == MQTT_CONNECTED)
          {
            xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
          }
        }
        second_cnt = 0;          //计时时间归零
        working_step = STEP_ALL; //状态???位
        HeatControl(0);
        // FanControl(0);  //关???机
      } //else if
    }   //定时
  }     //if
}

/**
  * @brief  主要是针对母婴驱蚊模式
  * @param  无
  * @retval 无
  */
void RepelMaternal(void)
{
  if (ConfigParam.WorkingMode.work_mode_data.working_mode == ENUM_REPEL_MATERNAL_MODE) //驱蚊
  {
    // ENUM_MOS_REPEL_NORMAL,
    // ENUM_MOS_REPEL_TIMING,
    if (ConfigParam.RepelSetting.repel_sett_data.repel_sett_mode == ENUM_MOS_REPEL_NORMAL)
    {
      if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_READY)
      {
        HeatControl(1);
        // FanControl(1);
        second_cnt = ConfigParam.FactorySetting.factory_sett_data.InitRepelTime * 60;
        working_step = STEP1;
        ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_WAIT;
      }
      else if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_WAIT)
      {
        if (second_cnt > 0)
        {
          second_cnt--;
        }
        if (working_step == STEP1)
        { //在这里等待加热完成(这个时间里驱蚊开)
          if (second_cnt == 0)
          {
            ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_START;
            working_step = STEP2; //
          }
          if (ConfigParam.RepelSetting.repel_sett_data.total_repel_time > 0)
          {                                                              //如果还有驱蚊药剂的话
            ConfigParam.RepelSetting.repel_sett_data.total_repel_time--; //每隔1s药剂总时间,得减1
            if (ConfigParam.RepelSetting.repel_sett_data.total_repel_time % 1800 == 0)
            { //每个30min对药剂时间进行存储
              write_config_param(&ConfigParam.RepelSetting.repel_sett_data.repel_sett_mode, ConfigParam.RepelSetting.pC, ConfigParam.RepelSetting.length);
            }
          }
          else
          { //这里是驱蚊药水用完了的情况
            ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_STOP;
            IsChangeMenu = true; //重绘界面

            //发送当前状态
            mqtt_pub_queue_enum = MQTT_SEND_STATE;
            pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
            if (mqtt_is_connected == MQTT_CONNECTED)
            {
              xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
            }
          }
        }
        if (working_step == STEP3)
        { //在这里等待加热开始(这个时间里驱蚊关)
          if (second_cnt == 0)
          {
            ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_START;
            working_step = STEP4;
          }
        }
      }
      else if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_START)
      { //表示关驱蚊加热
        if (working_step == STEP2)
        {
          switch (ConfigParam.RepelSetting.repel_sett_data.repel_sett_area)
          { //根据当前的面??来???算具体的驱蚊开关时??(这里表示关闭的时??)  这里的智能???测没有做
          case ENUM_21_30_M2:
            second_cnt = ConfigParam.FactorySetting.factory_sett_data.area30m2_factory * ConfigParam.FactorySetting.factory_sett_data.maternal_close_time * 60UL / 100;
            break;
          case ENUM_10_20_M2:
            second_cnt = ConfigParam.FactorySetting.factory_sett_data.area20m2_factory * ConfigParam.FactorySetting.factory_sett_data.maternal_close_time * 60UL / 100;
            break;
          case ENUM_BENEATH_10M2:
            second_cnt = ConfigParam.FactorySetting.factory_sett_data.area10m2_factory * ConfigParam.FactorySetting.factory_sett_data.maternal_close_time * 60UL / 100;
            break;
          default:
            second_cnt = ConfigParam.FactorySetting.factory_sett_data.area30m2_factory * ConfigParam.FactorySetting.factory_sett_data.maternal_close_time * 60UL / 100;
            break;
          }
          HeatControl(0);
          // FanControl(0);  //关???机
          ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_WAIT;
          working_step = STEP3;
        }
        if (working_step == STEP4)
        { //表示驱蚊开
          switch (ConfigParam.RepelSetting.repel_sett_data.repel_sett_area)
          { //根据当前的面??来???算具体的驱蚊开关时??(这里表示开??的时??)  这里的智能???测没有做
          case ENUM_21_30_M2:
            second_cnt = ConfigParam.FactorySetting.factory_sett_data.area30m2_factory * ConfigParam.FactorySetting.factory_sett_data.maternal_open_time * 60UL / 100;
            break;
          case ENUM_10_20_M2:
            second_cnt = ConfigParam.FactorySetting.factory_sett_data.area20m2_factory * ConfigParam.FactorySetting.factory_sett_data.maternal_open_time * 60UL / 100;
            break;
          case ENUM_BENEATH_10M2:
            second_cnt = ConfigParam.FactorySetting.factory_sett_data.area10m2_factory * ConfigParam.FactorySetting.factory_sett_data.maternal_open_time * 60UL / 100;
            break;
          default:
            second_cnt = ConfigParam.FactorySetting.factory_sett_data.area30m2_factory * ConfigParam.FactorySetting.factory_sett_data.maternal_open_time * 60UL / 100;
            break;
          }
          HeatControl(1); //开加热
          // FanControl(1);  //开风机
          ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_WAIT;
          working_step = STEP1;
        }
      }
      else if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_STOP)
      {
        //IsChangeMenu=true;  //重绘界面   这里不能重绘
        second_cnt = 0;          //计时时间归零
        working_step = STEP_ALL; //状态???位
        HeatControl(0);
        // FanControl(0);  //关???机
      }
    }
    else if (ConfigParam.RepelSetting.repel_sett_data.repel_sett_mode == ENUM_MOS_REPEL_TIMING)
    {                               //这里??针???定时驱蚊的情况  在这种情况下??有时间到了才开始驱??
      uint16_t current_minutes = 0; //当前分钟
      uint16_t start_minutes = 0;   //开始分??
      uint16_t end_minutes = 0;     //结束分钟
      static uint8_t mark1 = 0;

      current_minutes = (current_time.tm_hour * (uint32_t)60) + current_time.tm_min; //这里向uint16_t转变是为了防止变量值溢出
      start_minutes = ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.Start_Hour * (uint16_t)60;
      end_minutes = ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.End_Hour * (uint16_t)60;

      if (ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.End_Hour > ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.Start_Hour)
      { //结束时间必须大于开始时??
        if (start_minutes <= current_minutes && current_minutes < end_minutes)
        {
          if (timing_repel_pause == 1) //按下启动键
          {                            //暂停
            if (ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.IsRepeat == true)
            { //点了每天,到点就开??       //有些参数变化,完成后得妥善保存
              mark = 1;
            }
            else if (repel_once_mark == 1)
            { //没有点每天
              repel_once_mark = 0;
              mark = 1;
            }
          }
        }
        else
        { //否则停机
          mark = 0;
        }
      }
      else if (ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.End_Hour < ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.Start_Hour)
      { //结束时间小于开始时间的情况   ,这种情况是指,隔天的情况
        if (!(start_minutes > current_minutes && current_minutes >= end_minutes))
        {                              //这里是从反方向来考虑的
          if (timing_repel_pause == 1) //按下了启动键
          {
            if (ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.IsRepeat == true)
            { //点了每天,到点就开??
              mark = 1;
            }
            else if (repel_once_mark == 1)
            { //没有点每天
              repel_once_mark = 0;
              mark = 1;
            }
          }
        }
        else
        { //否则停机
          mark = 0;
        }
      }
      else
      {
        //否则停机
        mark = 0;
      }
      /**
     * 上面是监控函数
     */
      if (mark == 1)
      {
        if (mark1 == 0)
        {
          mark1 = 1;
          ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_READY;
          IsChangeMenu = true;
          //发送当前状态
          mqtt_pub_queue_enum = MQTT_SEND_STATE;
          pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
          if (mqtt_is_connected == MQTT_CONNECTED)
          {
            xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
          }
        }
        else if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_READY)
        {
          HeatControl(1); //开蚊加热
          // FanControl(1);
          second_cnt = ConfigParam.FactorySetting.factory_sett_data.InitRepelTime * 60;
          working_step = STEP1;
          ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_WAIT;
        }
        else if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_WAIT)
        {
          if (second_cnt > 0)
          {
            second_cnt--;
          }
          if (working_step == STEP1)
          { //在这里等待加热完成(这段时间里驱蚊开)
            if (second_cnt == 0)
            {
              ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_START;
              working_step = STEP2; //
            }
            if (ConfigParam.RepelSetting.repel_sett_data.total_repel_time > 0)
            {                                                              //如果还有驱蚊药剂的话
              ConfigParam.RepelSetting.repel_sett_data.total_repel_time--; //每隔1s药剂总时间,得减1
              if (ConfigParam.RepelSetting.repel_sett_data.total_repel_time % 1800 == 0)
              { //每个30min对药剂时间进行存储
                write_config_param(&ConfigParam.RepelSetting.repel_sett_data.repel_sett_mode, ConfigParam.RepelSetting.pC, ConfigParam.RepelSetting.length);
              }
            }
            else
            {                         //这里是驱蚊药水已经用完了的情况
              timing_repel_pause = 0; //定时驱蚊暂停
              mark = 0;               //按下停止键时不管三七二十一直接停止
              stop_refresh = 1;
            }
          }
          if (working_step == STEP3)
          { //在这里等待驱蚊开(这段时间里驱蚊关闭)
            if (second_cnt == 0)
            {
              ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_START;
              working_step = STEP4;
            }
          }
        }
        else if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_START)
        {
          if (working_step == STEP2)
          {
            switch (ConfigParam.RepelSetting.repel_sett_data.repel_sett_area)
            {
            case ENUM_21_30_M2:
              second_cnt = ConfigParam.FactorySetting.factory_sett_data.area30m2_factory * ConfigParam.FactorySetting.factory_sett_data.maternal_close_time * 60UL / 100;
              break;
            case ENUM_10_20_M2:
              second_cnt = ConfigParam.FactorySetting.factory_sett_data.area20m2_factory * ConfigParam.FactorySetting.factory_sett_data.maternal_close_time * 60UL / 100;
              break;
            case ENUM_BENEATH_10M2:
              second_cnt = ConfigParam.FactorySetting.factory_sett_data.area10m2_factory * ConfigParam.FactorySetting.factory_sett_data.maternal_close_time * 60UL / 100;
              break;
            default:
              second_cnt = ConfigParam.FactorySetting.factory_sett_data.area30m2_factory * ConfigParam.FactorySetting.factory_sett_data.maternal_close_time * 60UL / 100;
              break;
            }
            HeatControl(0);
            // FanControl(0);  //关机
            ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_WAIT;
            working_step = STEP3;
          }
          if (working_step == STEP4)
          {
            switch (ConfigParam.RepelSetting.repel_sett_data.repel_sett_area)
            {
            case ENUM_21_30_M2:
              second_cnt = ConfigParam.FactorySetting.factory_sett_data.area30m2_factory * ConfigParam.FactorySetting.factory_sett_data.maternal_open_time * 60UL / 100;
              break;
            case ENUM_10_20_M2:
              second_cnt = ConfigParam.FactorySetting.factory_sett_data.area20m2_factory * ConfigParam.FactorySetting.factory_sett_data.maternal_open_time * 60UL / 100;
              break;
            case ENUM_BENEATH_10M2:
              second_cnt = ConfigParam.FactorySetting.factory_sett_data.area10m2_factory * ConfigParam.FactorySetting.factory_sett_data.maternal_open_time * 60UL / 100;
              break;
            default:
              second_cnt = ConfigParam.FactorySetting.factory_sett_data.area30m2_factory * ConfigParam.FactorySetting.factory_sett_data.maternal_open_time * 60UL / 100;
              break;
            }
            HeatControl(1); //开加热
            // FanControl(1);  //开风机
            ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_WAIT;
            working_step = STEP1;
          }
        }
      }
      else if (mark == 0)
      {
        if (mark1 == 1 || stop_refresh == 1)
        { //上面的两个变量,确保停止界面只刷新一次
          mark1 = 0;
          stop_refresh = 0;
          ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_STOP;
          IsChangeMenu = true; //重绘界面
                               //发送当前状态
          mqtt_pub_queue_enum = MQTT_SEND_STATE;
          pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
          if (mqtt_is_connected == MQTT_CONNECTED)
          {
            xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
          }
        }
        second_cnt = 0;          //计时时间归零
        working_step = STEP_ALL; //状态???位
        HeatControl(0);
        // FanControl(0);  //关???机
      }
    }
  }
}

/**
  * @brief  主要是针对香薰模式
  * @param  无
  * @retval 无
  */
void RepelAroma(void)
{
  if (ConfigParam.WorkingMode.work_mode_data.working_mode == ENUM_AROMA_MODE) //香薰
  {
    // ENUM_MOS_REPEL_NORMAL,
    // ENUM_MOS_REPEL_TIMING,
    if (ConfigParam.RepelSetting.repel_sett_data.repel_sett_mode == ENUM_MOS_REPEL_NORMAL)
    {
      if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_READY)
      {
        HeatControl(1); //开驱蚊加热
        // FanControl(1);
        second_cnt = ConfigParam.FactorySetting.factory_sett_data.InitRepelTime * 60;
        working_step = STEP1;
        ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_WAIT;
      }
      else if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_WAIT)
      { //这里??等待状??
        if (second_cnt > 0)
        {
          second_cnt--;
        }
        if (working_step == STEP1)
        { //在这里等待加热完成(这段时间里驱蚊加热一直开着)
          if (second_cnt == 0)
          {
            ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_START;
            working_step = STEP2; //
          }
          if (ConfigParam.RepelSetting.repel_sett_data.total_repel_time > 0)
          {                                                              //如果还有驱蚊药剂的话
            ConfigParam.RepelSetting.repel_sett_data.total_repel_time--; //每隔1s药剂总时间,得减1
            if (ConfigParam.RepelSetting.repel_sett_data.total_repel_time % 1800 == 0)
            { //每个30min对药剂时间进行存储
              write_config_param(&ConfigParam.RepelSetting.repel_sett_data.repel_sett_mode, ConfigParam.RepelSetting.pC, ConfigParam.RepelSetting.length);
            }
          }
          else
          { //这里是驱蚊药水用完了的情况
            ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_STOP;
            IsChangeMenu = true; //重绘界面
            mqtt_pub_queue_enum = MQTT_SEND_STATE;
            pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
            if (mqtt_is_connected == MQTT_CONNECTED)
            {
              xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
            }
          }
        }
        if (working_step == STEP3)
        { //在这里等待驱蚊开启(这段时间里驱蚊是关闭的)
          if (second_cnt == 0)
          {
            ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_START;
            working_step = STEP4;
          }
        }
      }
      else if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_START)
      {
        if (working_step == STEP2)
        {
          switch (ConfigParam.RepelSetting.repel_sett_data.repel_sett_area)
          {
          case ENUM_21_30_M2:
            second_cnt = ConfigParam.FactorySetting.factory_sett_data.area30m2_factory * ConfigParam.FactorySetting.factory_sett_data.normal_close_time * 60UL / 100;
            break;
          case ENUM_10_20_M2:
            second_cnt = ConfigParam.FactorySetting.factory_sett_data.area20m2_factory * ConfigParam.FactorySetting.factory_sett_data.normal_close_time * 60UL / 100;
            break;
          case ENUM_BENEATH_10M2:
            second_cnt = ConfigParam.FactorySetting.factory_sett_data.area10m2_factory * ConfigParam.FactorySetting.factory_sett_data.normal_close_time * 60UL / 100;
            break;
          default:
            second_cnt = ConfigParam.FactorySetting.factory_sett_data.area30m2_factory * ConfigParam.FactorySetting.factory_sett_data.normal_close_time * 60UL / 100;
            break;
          }
          HeatControl(0);
          // FanControl(0);
          ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_WAIT;
          working_step = STEP3;
        }
        if (working_step == STEP4)
        {
          switch (ConfigParam.RepelSetting.repel_sett_data.repel_sett_area)
          {
          case ENUM_21_30_M2:
            second_cnt = ConfigParam.FactorySetting.factory_sett_data.area30m2_factory * ConfigParam.FactorySetting.factory_sett_data.normal_open_time * 60UL / 100;
            break;
          case ENUM_10_20_M2:
            second_cnt = ConfigParam.FactorySetting.factory_sett_data.area20m2_factory * ConfigParam.FactorySetting.factory_sett_data.normal_open_time * 60UL / 100;
            break;
          case ENUM_BENEATH_10M2:
            second_cnt = ConfigParam.FactorySetting.factory_sett_data.area10m2_factory * ConfigParam.FactorySetting.factory_sett_data.normal_open_time * 60UL / 100;
            break;
          default:
            second_cnt = ConfigParam.FactorySetting.factory_sett_data.area30m2_factory * ConfigParam.FactorySetting.factory_sett_data.normal_open_time * 60UL / 100;
            break;
          }
          HeatControl(1); //开加热
          // FanControl(1);  //开风机
          ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_WAIT;
          working_step = STEP1;
        }
      }
      else if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_STOP)
      {
        //IsChangeMenu=true;  //重绘界面   这里不能重绘
        second_cnt = 0;          //计时时间归零
        working_step = STEP_ALL; //状态???位
        HeatControl(0);
        // FanControl(0);  //关???机
      }
    }
    else if (ConfigParam.RepelSetting.repel_sett_data.repel_sett_mode == ENUM_MOS_REPEL_TIMING)
    {
      uint16_t current_minutes = 0; //当前分钟
      uint16_t start_minutes = 0;   //开始分??
      uint16_t end_minutes = 0;     //结束分钟
      static uint8_t mark1 = 0;     //??做一次启??(探测变化)

      current_minutes = (current_time.tm_hour * (uint32_t)60) + current_time.tm_min; //这里向uint16_t转变是为了防止变量值溢出
      start_minutes = ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.Start_Hour * (uint16_t)60;
      end_minutes = ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.End_Hour * (uint16_t)60;

      if (ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.End_Hour > ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.Start_Hour)
      { //结束时间必须大于开始时间
        if (start_minutes <= current_minutes && current_minutes < end_minutes)
        {                              //到点??
          if (timing_repel_pause == 1) //点了开始键
          {
            if (ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.IsRepeat == true)
            { //点了每天,到点就开??       //有些参数变化,完成后得妥善保存
              mark = 1;
            }
            else if (repel_once_mark == 1)
            { //没有点每??
              repel_once_mark = 0;
              mark = 1;
            }
          }
        }
        else
        { //否则停机
          mark = 0;
        }
      }
      else if (ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.End_Hour < ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.Start_Hour)
      { //结束时间小于开始时间的情况   ,这种情况是指,隔天的情况
        if (!(start_minutes > current_minutes && current_minutes >= end_minutes))
        {                              //这里是从反方向来考虑的
          if (timing_repel_pause == 1) //       按下了启动键
          {
            if (ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.IsRepeat == true)
            { //点了每天,到点就开??
              mark = 1;
            }
            else if (repel_once_mark == 1)
            { //没有点每??
              repel_once_mark = 0;
              mark = 1;
            }
          }
        }
        else
        { //否则停机
          mark = 0;
        }
      }
      else
      {
        //否则停机
        mark = 0;
      }
      /**
       * 上面是监控函数
       */
      if (mark == 1)
      {
        if (mark1 == 0)
        {
          mark1 = 1;
          ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_READY;
          IsChangeMenu = true; //这里得刷新一下显示
                               //向APP发送当前状态
          mqtt_pub_queue_enum = MQTT_SEND_STATE;
          pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
          if (mqtt_is_connected == MQTT_CONNECTED)
          {
            xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
          }
        }
        else if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_READY)
        {
          HeatControl(1);
          // FanControl(1);
          second_cnt = ConfigParam.FactorySetting.factory_sett_data.InitRepelTime * 60;
          working_step = STEP1;
          ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_WAIT;
        }
        else if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_WAIT)
        {
          if (second_cnt > 0)
          {
            second_cnt--;
          }
          if (working_step == STEP1)
          { //在这里等待加热完成(这段时间里驱蚊已经开启了)
            if (second_cnt == 0)
            {
              ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_START;
              working_step = STEP2; //
            }
            if (ConfigParam.RepelSetting.repel_sett_data.total_repel_time > 0)
            {                                                              //如果还有驱蚊药剂的话
              ConfigParam.RepelSetting.repel_sett_data.total_repel_time--; //每隔1s药剂总时间,得减1
              if (ConfigParam.RepelSetting.repel_sett_data.total_repel_time % 1800 == 0)
              { //每个30min对药剂时间进行存储
                write_config_param(&ConfigParam.RepelSetting.repel_sett_data.repel_sett_mode, ConfigParam.RepelSetting.pC, ConfigParam.RepelSetting.length);
              }
            }
            else
            {                         //这里是驱蚊药水已经用完了的情况
              timing_repel_pause = 0; //定时驱蚊暂停
              mark = 0;               //按下停止键时不管三七二十一直接停止
              stop_refresh = 1;
            }
          }
          if (working_step == STEP3)
          { //在这里等待驱蚊开启(这段时间里驱蚊已关闭)
            if (second_cnt == 0)
            {
              ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_START;
              working_step = STEP4;
            }
          }
        }
        else if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_START)
        {
          if (working_step == STEP2)
          {
            switch (ConfigParam.RepelSetting.repel_sett_data.repel_sett_area)
            {
            case ENUM_21_30_M2:
              second_cnt = ConfigParam.FactorySetting.factory_sett_data.area30m2_factory * ConfigParam.FactorySetting.factory_sett_data.normal_close_time * 60UL / 100;
              break;
            case ENUM_10_20_M2:
              second_cnt = ConfigParam.FactorySetting.factory_sett_data.area20m2_factory * ConfigParam.FactorySetting.factory_sett_data.normal_close_time * 60UL / 100;
              break;
            case ENUM_BENEATH_10M2:
              second_cnt = ConfigParam.FactorySetting.factory_sett_data.area10m2_factory * ConfigParam.FactorySetting.factory_sett_data.normal_close_time * 60UL / 100;
              break;
            default:
              second_cnt = ConfigParam.FactorySetting.factory_sett_data.area30m2_factory * ConfigParam.FactorySetting.factory_sett_data.normal_close_time * 60UL / 100;
              break;
            }
            HeatControl(0);
            // FanControl(0);
            ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_WAIT;
            working_step = STEP3;
          }
          if (working_step == STEP4)
          {
            switch (ConfigParam.RepelSetting.repel_sett_data.repel_sett_area)
            {
            case ENUM_21_30_M2:
              second_cnt = ConfigParam.FactorySetting.factory_sett_data.area30m2_factory * ConfigParam.FactorySetting.factory_sett_data.normal_open_time * 60UL / 100;
              break;
            case ENUM_10_20_M2:
              second_cnt = ConfigParam.FactorySetting.factory_sett_data.area20m2_factory * ConfigParam.FactorySetting.factory_sett_data.normal_open_time * 60UL / 100;
              break;
            case ENUM_BENEATH_10M2:
              second_cnt = ConfigParam.FactorySetting.factory_sett_data.area10m2_factory * ConfigParam.FactorySetting.factory_sett_data.normal_open_time * 60UL / 100;
              break;
            default:
              second_cnt = ConfigParam.FactorySetting.factory_sett_data.area30m2_factory * ConfigParam.FactorySetting.factory_sett_data.normal_open_time * 60UL / 100;
              break;
            }
            HeatControl(1); //开加热
            // FanControl(1);  //开风机
            ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_WAIT;
            working_step = STEP1;
          }
        }
      }
      else if (mark == 0)
      {
        if (mark1 == 1 || stop_refresh == 1)
        {
          mark1 = 0;
          stop_refresh = 0;
          ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_STOP;
          IsChangeMenu = true; //重绘界面
                               //给APP发送到当前状态
          mqtt_pub_queue_enum = MQTT_SEND_STATE;
          pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
          if (mqtt_is_connected == MQTT_CONNECTED)
          {
            xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
          }
        }
        second_cnt = 0;          //计时时间归零
        working_step = STEP_ALL; //状态???位
        HeatControl(0);
        // FanControl(0);  //关???机
      }
    }
  }
}

/**
  * @brief  主要是针对增强驱蚊模式
  * @param  无
  * @retval 无
  */
void RepelEnchance(void)
{
  if (ConfigParam.WorkingMode.work_mode_data.working_mode == ENUM_REPEL_ENCHANCE_MODE) //驱蚊
  {
    // ENUM_MOS_REPEL_NORMAL,
    // ENUM_MOS_REPEL_TIMING,
    if (ConfigParam.RepelSetting.repel_sett_data.repel_sett_mode == ENUM_MOS_REPEL_NORMAL)
    {
      if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_READY)
      {
        HeatControl(1);
        // FanControl(1);
        if (ConfigParam.RepelSetting.repel_sett_data.total_repel_time > 0)
        {                                                              //如果还有驱蚊药剂的话
          ConfigParam.RepelSetting.repel_sett_data.total_repel_time--; //每隔1s药剂总时间,得减1
          if (ConfigParam.RepelSetting.repel_sett_data.total_repel_time % 1800 == 0)
          { //每个30min对药剂时间进行存储
            write_config_param(&ConfigParam.RepelSetting.repel_sett_data.repel_sett_mode, ConfigParam.RepelSetting.pC, ConfigParam.RepelSetting.length);
          }
        }
        else
        { //这里是驱蚊药水用完了的情况
          ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_STOP;
          IsChangeMenu = true; //重绘界面
                               //这里发送当前灭蚊器状态
          mqtt_pub_queue_enum = MQTT_SEND_STATE;
          pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
          if (mqtt_is_connected == MQTT_CONNECTED)
          {
            xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
          }
        }
      }
      else if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_STOP)
      {
        //IsChangeMenu=true;  //重绘界面   这里不能重绘
        second_cnt = 0;          //计时时间归零
        working_step = STEP_ALL; //状态???位
        HeatControl(0);
        // FanControl(0);
      }
    }
    else if (ConfigParam.RepelSetting.repel_sett_data.repel_sett_mode == ENUM_MOS_REPEL_TIMING)
    {
      uint16_t current_minutes = 0; //当前分钟
      uint16_t start_minutes = 0;   //开始分??
      uint16_t end_minutes = 0;     //结束分钟
      static uint8_t mark1 = 0;

      current_minutes = (current_time.tm_hour * (uint32_t)60) + current_time.tm_min; //这里向uint16_t转变是为了防止变量值溢出
      start_minutes = ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.Start_Hour * (uint16_t)60;
      end_minutes = ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.End_Hour * (uint16_t)60;

      if (ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.End_Hour > ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.Start_Hour)
      { //结束时间必须大于开始时??
        if (start_minutes <= current_minutes && current_minutes < end_minutes)
        {                              //到点
          if (timing_repel_pause == 1) //       按下了启动键
          {
            if (ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.IsRepeat == true)
            { //点了每天,到点就开??       //有些参数变化,完成后得妥善保存
              mark = 1;
            }
            else if (repel_once_mark == 1)
            { //没有点每天
              repel_once_mark = 0;
              mark = 1;
            }
          }
        }
        else
        { //否则停机
          mark = 0;
        }
      }
      else if (ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.End_Hour < ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.Start_Hour)
      { //结束时间小于开始时间的情况   ,这种情况是指,隔天的情况
        if (!(start_minutes > current_minutes && current_minutes >= end_minutes))
        {                              //这里是从反方向来考虑的
          if (timing_repel_pause == 1) //       按下了启动键
          {
            if (ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.IsRepeat == true)
            { //点了每天,到点就开??
              mark = 1;
            }
            else if (repel_once_mark == 1)
            { //没有点每??
              repel_once_mark = 0;
              mark = 1;
            }
          }
        }
        else
        { //否则停机
          mark = 0;
        }
      }
      else
      {
        //否则停机
        mark = 0;
      }
      /**
       * 上面是监控函数
       */
      if (mark == 1)
      {
        if (mark1 == 0)
        {
          mark1 = 1;
          HeatControl(1);
          // FanControl(1);
          ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_READY;
          IsChangeMenu = true; //这里得刷新一下显??
                               //这里发送当前灭蚊器状态
          mqtt_pub_queue_enum = MQTT_SEND_STATE;
          pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
          if (mqtt_is_connected == MQTT_CONNECTED)
          {
            xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
          }
        }
        if (ConfigParam.RepelSetting.repel_sett_data.total_repel_time > 0)
        {                                                              //如果还有驱蚊药剂的话
          ConfigParam.RepelSetting.repel_sett_data.total_repel_time--; //每隔1s药剂总时间,得减1
          if (ConfigParam.RepelSetting.repel_sett_data.total_repel_time % 1800 == 0)
          { //每个30min对药剂时间进行存储
            write_config_param(&ConfigParam.RepelSetting.repel_sett_data.repel_sett_mode, ConfigParam.RepelSetting.pC, ConfigParam.RepelSetting.length);
          }
        }
        else
        {                         //这里是驱蚊药水已经用完了的情况
          timing_repel_pause = 0; //定时驱蚊暂停
          mark = 0;               //按下停止键时不管三七二十一直接停止
          stop_refresh = 1;       //停止界面得及时刷新
        }
      }
      else if (mark == 0)
      {
        if (mark1 == 1 || stop_refresh == 1)
        {
          mark1 = 0;
          stop_refresh = 0;
          ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_STOP;
          IsChangeMenu = true; //重绘界面
                               //这里发送当前灭蚊器状态
          mqtt_pub_queue_enum = MQTT_SEND_STATE;
          pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
          if (mqtt_is_connected == MQTT_CONNECTED)
          {
            xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
          }
        }
        second_cnt = 0;          //计时时间归零
        working_step = STEP_ALL; //状态???位
        HeatControl(0);
        // FanControl(0);  //关???机
      }
    }
  }
}

/***********************************************************************/

void AutoBacklight(void)
{
  if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_STOP)
  {
    ConfigParam.RepelSetting.repel_sett_data.backlight = 0;
    write_config_param(&ConfigParam.RepelSetting.repel_sett_data.repel_sett_mode, ConfigParam.RepelSetting.pC, ConfigParam.RepelSetting.length);
  }
}

void ManualBacklight(void)
{
  if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_STOP)
  {
    ConfigParam.RepelSetting.repel_sett_data.backlight = 0;
    //write_config_param(&ConfigParam.RepelSetting.repel_sett_data.repel_sett_mode, ConfigParam.RepelSetting.pC, ConfigParam.RepelSetting.length);
  }
}

/**
  * @brief  设置当前驱蚊模式为连续定时
  * @param  越是困难才越有意义！(轻轻松松就成功了,那多没意思呀!)
  * @retval 无
  */
void RepelTimeRepeat(void)
{
  if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_STOP)
  {
    if (ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.IsRepeat == false)
    {
      ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.IsRepeat = true; //每天被按下
      timing_repel_pause = 0;                                                     //定时驱蚊暂停
      write_config_param(&ConfigParam.RepelSetting.repel_sett_data.repel_sett_mode, ConfigParam.RepelSetting.pC, ConfigParam.RepelSetting.length);
      IsChangeMenu = true;
    }
  }
}

/**
  * @brief  设置当前驱蚊模式为一次定时
  * @param  越是困难才越有意义！(轻轻松松就成功了,那多没意思呀!)
  * @retval 无
  */
void RepelTimeNotRepeat(void)
{
  if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_STOP)
  {
    if (ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.IsRepeat == true)
    {
      ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.IsRepeat = false; //单次被按下
      timing_repel_pause = 0;                                                      //定时驱蚊暂停
      write_config_param(&ConfigParam.RepelSetting.repel_sett_data.repel_sett_mode, ConfigParam.RepelSetting.pC, ConfigParam.RepelSetting.length);
      IsChangeMenu = true;
    }
  }
}

/**
  * @brief  设置当前驱蚊模式为定时
  * @param  越是困难才越有意义！(轻轻松松就成功了,那多没意思呀!)
  * @retval 无
  */
void RepelTimingSett(void)
{
  if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_STOP)
  {
    ConfigParam.RepelSetting.repel_sett_data.repel_sett_mode = ENUM_MOS_REPEL_TIMING;
    // ConfigParam.RepelSetting.repel_sett_data.repel_sett_mode = ENUM_MOS_REPEL_NORMAL;
    write_config_param(&ConfigParam.RepelSetting.repel_sett_data.repel_sett_mode, ConfigParam.RepelSetting.pC, ConfigParam.RepelSetting.length);
  }
}

/**
  * @brief  设置当前驱蚊模式为非定时
  * @param  越是困难才越有意义！(轻轻松松就成功了,那多没意思呀!)
  * @retval 无
  */
void RepelNormalSettFunction(void)
{
  if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_STOP)
  {
    // ConfigParam.RepelSetting.repel_sett_data.repel_sett_mode = ENUM_MOS_REPEL_TIMING;
    ConfigParam.RepelSetting.repel_sett_data.repel_sett_mode = ENUM_MOS_REPEL_NORMAL;
    write_config_param(&ConfigParam.RepelSetting.repel_sett_data.repel_sett_mode, ConfigParam.RepelSetting.pC, ConfigParam.RepelSetting.length);
  }
}

/**
  * @brief  设置当前工作模式为增强灭蚊模式
  * @param  越是困难才越有意义！(轻轻松松就成功了,那多没意思呀!)
  * @retval 无
  */
void MosFumigateEnchanceFunction(void)
{
  if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_STOP)
  {
    ConfigParam.WorkingMode.work_mode_data.working_mode = ENUM_FUMIGATE_ENCHANCE_MODE;
    ConfigParam.WorkingMode.work_mode_data.fumigate_buf_mode = ENUM_FUMIGATE_ENCHANCE_MODE;
    write_config_param(&ConfigParam.WorkingMode.work_mode_data.working_mode, ConfigParam.WorkingMode.pC, ConfigParam.WorkingMode.length);
    IsChangeMenu = true; //重绘界面
  }
}

/**
  * @brief  设置当前工作模式为正常灭蚊模式
  * @param  越是困难才越有意义！(轻轻松松就成功了,那多没意思呀!)
  * @retval 无
  */
void MosFumigateNormalFunction(void)
{
  if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_STOP)
  {
    ConfigParam.WorkingMode.work_mode_data.working_mode = ENUM_FUMIGATE_NORMAL_MODE;
    ConfigParam.WorkingMode.work_mode_data.fumigate_buf_mode = ENUM_FUMIGATE_NORMAL_MODE;
    write_config_param(&ConfigParam.WorkingMode.work_mode_data.working_mode, ConfigParam.WorkingMode.pC, ConfigParam.WorkingMode.length);
    IsChangeMenu = true; //重绘界面
  }
}

/**
  * @brief  设置当前工作模式为增强驱蚊模式
  * @param  越是困难才越有意义！(轻轻松松就成功了,那多没意思呀!)
  * @retval 无
  */
void MosRepelEnchanceFunction(void)
{
  if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_STOP)
  {
    ConfigParam.WorkingMode.work_mode_data.working_mode = ENUM_REPEL_ENCHANCE_MODE;
    ConfigParam.WorkingMode.work_mode_data.repel_buf_mode = ENUM_REPEL_ENCHANCE_MODE;
    write_config_param(&ConfigParam.WorkingMode.work_mode_data.working_mode, ConfigParam.WorkingMode.pC, ConfigParam.WorkingMode.length);
    IsChangeMenu = true; //重绘界面
  }
}

/**
  * @brief  设置当前工作模式为母婴驱蚊模式
  * @param  越是困难才越有意义！(轻轻松松就成功了,那多没意思呀!)
  * @retval 无
  */
void MaternalFunction(void)
{
  if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_STOP)
  {
    ConfigParam.WorkingMode.work_mode_data.working_mode = ENUM_REPEL_MATERNAL_MODE;
    ConfigParam.WorkingMode.work_mode_data.repel_buf_mode = ENUM_REPEL_MATERNAL_MODE;
    write_config_param(&ConfigParam.WorkingMode.work_mode_data.working_mode, ConfigParam.WorkingMode.pC, ConfigParam.WorkingMode.length);
    IsChangeMenu = true; //重绘界面
  }
}

/**
  * @brief  设置当前工作模式为空调驱蚊模式
  * @param  越是困难才越有意义！(轻轻松松就成功了,那多没意思呀!)
  * @retval 无
  */
void AirConditionerFunction(void)
{
  if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_STOP)
  {
    ConfigParam.WorkingMode.work_mode_data.working_mode = ENUM_REPEL_AIR_CONDI_MODE;
    ConfigParam.WorkingMode.work_mode_data.repel_buf_mode = ENUM_REPEL_AIR_CONDI_MODE;
    write_config_param(&ConfigParam.WorkingMode.work_mode_data.working_mode, ConfigParam.WorkingMode.pC, ConfigParam.WorkingMode.length);
    IsChangeMenu = true; //重绘界面
  }
}

/**
  * @brief  设置当前工作模式为香薰
  * @param  越是困难才越有意义！(轻轻松松就成功了,那多没意思呀!)
  * @retval 无
  */
void MosAromaFunction(void)
{
  if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_STOP)
  {
    ConfigParam.WorkingMode.work_mode_data.working_mode = ENUM_AROMA_MODE;
    write_config_param(&ConfigParam.WorkingMode.work_mode_data.working_mode, ConfigParam.WorkingMode.pC, ConfigParam.WorkingMode.length);
    IsChangeMenu = true; //重绘界面
  }
}

/**
  * @brief  将驱蚊药液变为100%
  * @param  越是困难才越有意义！(轻轻松松就成功了,那多没意思呀!)
  * @retval 无
  */
void RefillRepelMedicine(void)
{
  if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_STOP)
  {
    ConfigParam.RepelSetting.repel_sett_data.total_repel_time = HOURS_OF_REPEL * 3600L;
    write_config_param(&ConfigParam.RepelSetting.repel_sett_data.repel_sett_mode, ConfigParam.RepelSetting.pC, ConfigParam.RepelSetting.length);
    percentage_of_repel_medicine = ConfigParam.RepelSetting.repel_sett_data.total_repel_time * 100UL / (HOURS_OF_REPEL * 3600L); //还剩百分之几的驱蚊药液  这里的时间是倒计时的
  }
}

/**
 * @brief  开机函数,既是针对灭蚊的,有是针对驱蚊和香薰的
 * @param  无 
 * @retval 无 
 */
void SwitchOn(void)
{ //这里只是控制状态,在control线程中会根据控制状态来决定开关
  ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_READY;
  timing_repel_pause = 1; //定时驱蚊/香薰功能开
  if (ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.IsRepeat == true)
  {
    repel_once_mark = 0;
  }
  else if (ConfigParam.RepelSetting.repel_sett_data.repel_sett_timing.IsRepeat == false)
  { //定时驱蚊/香薰功能只针对当天
    repel_once_mark = 1;
  }
  stop_refresh = 1; //时间区间不符合要求时,会立即显示停止
  Prev_UI = UI_ALL;
  IsChangeMenu = true; //立即刷新一些界面
                       /**
     *  //发送当前状态
     */
  mqtt_pub_queue_enum = MQTT_SEND_STATE;
  pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
  if (mqtt_is_connected == MQTT_CONNECTED)
  {
    xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
  }
}

/**
 * @brief  关机函数,既是针对灭蚊的,有是针对驱蚊和香薰的
 * @param  无 
 * @retval 无 
 */
void SwitchOff(void)
{
  ConfigParam.WorkingStatus.working_status_data = ENUM_WORKING_STOP;
  timing_repel_pause = 0; //定时驱蚊/香薰功能暂停
  mark = 0;               //不管三七二十一直接停止
  stop_refresh = 1;       //时间区间不符合要求时,会立即显示停止
  Prev_UI = UI_ALL;
  IsChangeMenu = true;
  /**
     *  //发送当前状态
     */
  mqtt_pub_queue_enum = MQTT_SEND_STATE;
  pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
  if (mqtt_is_connected == MQTT_CONNECTED)
  {
    xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
  }
}

/**
  * @brief  
  * @param  越是困难才越有意义！(轻轻松松就成功了,那多没意思呀!)
  * @retval 无
  */
void SmartconfigOrWifiSta(void)
{
    if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_STOP)
    { //这里得好好想一想
      if (ConfigParam.MQTT_Param.mqtt_param_data.wifi_mode == WIFI_SCANNING)
      {
        esp_smartconfig_stop();
        vTaskDelete(smartconfigTaskHandler);
        wifi_turnoff();
        ConfigParam.MQTT_Param.mqtt_param_data.wifi_mode = WIFI_CONNECT;
        write_config_param(&ConfigParam.MQTT_Param.mqtt_param_data.wifi_ssid, ConfigParam.MQTT_Param.pC, ConfigParam.MQTT_Param.length);
        current_wifi_state = WIFI_DISABLE;
        wifi_turnon();
      }
      else if (ConfigParam.MQTT_Param.mqtt_param_data.wifi_mode == WIFI_CONNECT)
      {
        mqtt_is_connected = MQTT_DISCONNECT;   //mqtt将要断开
        vTaskDelay(3000 / portTICK_PERIOD_MS); //等待3s让wifi通讯完成
        wifi_smartconfig();
      }
    }
}

/**                                      
  * @brief  根据当前是否处于驱蚊工作状态,来上报已驱蚊用时    
  * @param  无
  * @retval 无
  */
void ReportRepelAromaTime(void)
{
  static uint16_t cnt = 1;

  if (ConfigParam.WorkingMode.work_mode_data.working_mode == ENUM_REPEL_AIR_CONDI_MODE || ConfigParam.WorkingMode.work_mode_data.working_mode == ENUM_REPEL_MATERNAL_MODE || ConfigParam.WorkingMode.work_mode_data.working_mode == ENUM_REPEL_ENCHANCE_MODE)
  {
    if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_STOP)
    {
      cnt = 1;
    }
    else
    {
      if (cnt % 120 == 0)
      { //2min上报一次当前已工作的时间
        mqtt_pub_queue_enum = MQTT_SEND_REPEL_TIME;
        pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
        if (mqtt_is_connected == MQTT_CONNECTED)
        {
          xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
        }
      }
      cnt++;
    }
  }
  else if (ConfigParam.WorkingMode.work_mode_data.working_mode == ENUM_AROMA_MODE)
  {
    if (ConfigParam.WorkingStatus.working_status_data == ENUM_WORKING_STOP)
    {
      cnt = 1;
    }
    else
    {
      if (cnt % 120 == 0)
      { //2min上报一次当前已工作的时间
        mqtt_pub_queue_enum = MQTT_SEND_AROMA_TIME;
        pMQTT_PUB_QUEUE_ENUM = &mqtt_pub_queue_enum; //这里得是一个全局变量
        if (mqtt_is_connected == MQTT_CONNECTED)
        {
          xQueueSend(mqtt_pub_QueueHandler, (void *)&pMQTT_PUB_QUEUE_ENUM, portMAX_DELAY);
        }
      }
      cnt++;
    }
  }
}

/**
  * @brief  控制线程
  * @param  越是困难才越有意义！(轻轻松松就成功了,那多没意思呀!)
  * @retval 无
  */
void Control_Driver_Task(void *param)
{ //可以考虑状态机的工作方式  就绪-->等待-->工作-->停止
  // portMUX_TYPE Control_lock = portMUX_INITIALIZER_UNLOCKED;

  while (1)
  {
    get_time(0); //获取当前时间  //每隔1s一次
    // printf("%04d:%02d:%02d--%02d:%02d:%02d/n",current_time.tm_year,current_time.tm_mon,current_time.tm_mday,current_time.tm_hour,current_time.tm_min,current_time.tm_sec);
    //taskENTER_CRITICAL(&Control_lock);
    switch (ConfigParam.WorkingMode.work_mode_data.working_mode)
    {
    case ENUM_FUMIGATE_NORMAL_MODE:
      FumigateNormal();
      break;
    case ENUM_FUMIGATE_ENCHANCE_MODE:
      FumigateEnchance();
      break;
    case ENUM_REPEL_AIR_CONDI_MODE:
      RepelAirCondition();
      ReportRepelAromaTime();
      break;
    case ENUM_REPEL_MATERNAL_MODE:
      RepelMaternal();
      ReportRepelAromaTime();
      break;
    case ENUM_REPEL_ENCHANCE_MODE:
      RepelEnchance();
      ReportRepelAromaTime();
      break;
    case ENUM_AROMA_MODE:
      RepelAroma();
      ReportRepelAromaTime();
      break;
    default:
      break;
    } //switch
    //taskEXIT_CRITICAL(&Control_lock);
    vTaskDelay(1000 / portTICK_PERIOD_MS); //显示部分每隔1000ms刷新一次
  }                                        //while
}